package org.realteam.base.service;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class SpringContextPusher implements ApplicationContextAware {
	public final Log log = LogFactory.getLog(this.getClass());

	ApplicationContext applicationContext;

	static ApplicationContext staticApplicationContext;

	public void setApplicationContext(ApplicationContext applicationContext) {
		this.applicationContext = applicationContext;
		if (staticApplicationContext == null) {
			staticApplicationContext = this.applicationContext;
		}
	}

	public Object getBean(String beanName) {
		Object obj = this.applicationContext.getBean(beanName);
		if (obj == null) {
			throw new java.lang.IllegalArgumentException(" The bean's name of  " + beanName + " can not be found in spring container!");
		}
		return obj;
	}

	public static ApplicationContext getStaticApplicationContext() {
		return staticApplicationContext;
	}
}
